Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

332
Views
POST http://localhost:3001/[object%20Promise] 404 (No encontrado) React Axios

Aquí está mi código para enviar datos al servidor, pero siempre recibo este error.

 let data = { "email": "test@gmail.com", "language": "en", "country": "en", "istestentry": false }; let jsonData = JSON.stringify(data); let encodedData = encodeURIComponent(jsonData); let url = "https://example.org/b/receiver/external"; let fetchUrl = url + "?datajsonstr=" + encodedData + "&_=" + (new Date()).valueOf(); let datafetch = fetch(fetchUrl); const [fetchedData, setFetchedData] = useState(''); async function fetchData(){ const {data} = await axios.post( datafetch ) setFetchedData(data) } useEffect(() => { fetchData() }, []) const handleSubmit = (event) => { event.preventDefault(); fetchData() };

No sé cómo resolver este problema.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Está intentando enviar una promesa en lugar de datos en cadena. let datafetch = fetch(fetchUrl); te da una promesa. También el envío de datos a través de parámetros se realiza con solicitudes de get . Así que supongo que es posible que deba realizar una solicitud de get :

 let fetchUrl = url + "?datajsonstr=" + encodedData + "&_=" + (new Date()).valueOf(); const [fetchedData, setFetchedData] = useState(''); async function fetchData(){ const {data} = await axios.get(fetchUrl) setFetchedData(data) }

(PS get o post depende de cómo su API maneje las solicitudes. Puede elegir la correcta)

about 4 years ago · Juan Pablo Isaza Report

0

Lo resolví así. si no quieres usar Axios, puedes resolverlo también así.

const [dataDone, setDataDone] = useState(false);

 useEffect(() => { let data = { "email": "test@gmail.at", "language": "de", "country": "de", "istestentry": false }; let jsonData = JSON.stringify(data); let encodedData = encodeURIComponent(jsonData); let url = "https://org.com; let fetchUrl = url + "?datajsonstr=" + encodedData + "&_=" + (new Date()).valueOf(); let datafetch = fetch(fetchUrl); datafetch.then(data => { setDataDone(true) }) }, [])
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!